﻿
@{
    ViewData["Title"] = "分配权限";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
    var errmsg = TempData["errMsg"];
}
<div id="app" v-clock>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" action="@Url.Action("SetRole")" method="post" style="width: 60%;">
        @Html.AntiForgeryToken()
        <el-form-item>

        </el-form-item>
        <el-form-item>
            <el-transfer v-model="selectedData" v-bind:titles="titles" v-bind:button-texts="buttonTexts" v-bind:data="allrole"></el-transfer>
        </el-form-item>
        <input type="hidden" v-bind:value="v" v-bind:name="'list['+i+']'" v-for="(v,i) in selectedData" />
        <input type="hidden" value="@ViewBag.userId" name="userId" /> 
        <el-form-item>
            <el-button type="primary" @@click="submitForm('ruleForm')" size="small">保存</el-button>
            <el-button @@click="resetForm('ruleForm')" size="small">重置</el-button>
            <el-button icon="el-icon-back" size="small" @@click="funBack">返回 用户管理</el-button>
        </el-form-item>
    </el-form>
</div>
@section Scripts
    {
<script type="text/javascript">
        @if (errmsg!=null&&!string.IsNullOrEmpty(errmsg.ToString()))
        {
            //系统异常信息 输出
          @:$(function() { @(Html.Raw(errmsg)); });
        }

        new Vue({
            el: "#app",
            data:function () {
                return {
                    ruleForm: [],
                    allrole:@Html.Raw(ViewBag.AllRole),
                    titles:['未分配','已分配'],
                    buttonTexts:['收回','分配'],                 
                    rules: {},                
                    selectedData:@Html.Raw(ViewBag.selectedRole),
                };
            },
            mounted: function() {
                
            },
            methods: {
                submitForm: function(formName) {
                    this.$refs[formName].validate(function(valid) {
                        if (valid) {
                            $("form").eq(0).submit();
                        } else {
                            return false;
                        }
                    }); 
                },
                resetForm: function(formName) {
                    //this.$refs[formName].resetFields();
                    this.$refs.tree.setCheckedKeys([]);
                },
                funBack: function() {
                    window.history.go(-1);
                },
                funLoad: function() {
                    this.selectedData = this.$refs.tree.getCheckedNodes().selectFun(function (x) { return x.FullParentId+'='+x.FunctionId; });
                }
            }
        })
</script>
}
